﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using FJERP.Model;

namespace FJERP.DAL
{
    public class StatisticsShipmentsDAL
    {
        SQLHelper h = new SQLHelper();
        /// <summary>
        /// 查询年份
        /// </summary>
        /// <param name="TimeStart"></param>
        /// <param name="TimeEnd"></param>
        /// <returns></returns>
        public List<SearchYear> SearchY(string TimeStart, string TimeEnd)
        {
            string sql = "select YEAR(Purchase_date) as 年,SUM(SumMoney) as 总金额 from Purchase where year(Purchase_date) between '" + TimeStart + "' and '" + TimeEnd + "'  group by YEAR(Purchase_date) ";
            List<SearchYear> list = new List<SearchYear>();
            DataTable data = h.ExecDataTable(sql);
            foreach (DataRow item in data.Rows)
            {
                SearchYear p = new SearchYear();
                p.YearNum = item["年"].ToString();
                p.YearMoney = item["总金额"].ToString();
                list.Add(p);
            }
            return list;
        }
        /// <summary>
        /// 查询月份
        /// </summary>
        /// <param name="SYear"></param>
        /// <param name="TimeStart"></param>
        /// <param name="TimeEnd"></param>
        /// <returns></returns>
        public List<SearchMonth> SearchM(string SYear, string TimeStart, string TimeEnd)
        {
            string sql = "select Month(Purchase_date) as 月,SUM(SumMoney) as 总金额 from Purchase  where year(Purchase_date) ='" + SYear + "' and MONTH(Purchase_date) between '" + TimeStart + "' and '" + TimeEnd + "' group by Month(Purchase_date)";
            List<SearchMonth> list = new List<SearchMonth>();
            DataTable data = h.ExecDataTable(sql);
            foreach (DataRow item in data.Rows)
            {
                SearchMonth p = new SearchMonth();
                p.MonthNum = item["月"].ToString();
                p.MonthMoney = item["总金额"].ToString();
                list.Add(p);
            }
            return list;
        }
    }
}
